package org.example.hengshengexam;

public class BankAccount {
    private double balance; // 账户余额
    // 存款
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            System.out.println("存款 " + amount + " 元成功，当前余额：" + balance);
        } else {
            System.out.println("存款金额不能为负");
        }
    }
    // 取款
    public void withdraw(double amount) {
        if (amount > 0 && amount <= balance) {
            balance -= amount;
            System.out.println("取款 " + amount + " 元成功，当前余额：" + balance);
        } else {
            System.out.println("取款金额无效或余额不足");
        }
    }
    // 查询余额
    public double checkBalance() {
        return balance;
    }
    // 主方法测试
    public static void main(String[] args) {
        BankAccount account = new BankAccount();
        account.deposit(1000);
        account.withdraw(500);
        System.out.println("最终余额：" + account.checkBalance());
    }
}